package com.jysz.certificate.persistence.dao.system;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.jysz.certificate.persistence.dao.AbstractBaseDao;
import com.jysz.certificate.persistence.model.core.SystemPreferences;

/**
 * @author <a href="mailto:javaengine@outlook.com">Kaca Rich</a>
 *
 */
@Repository
public class SystemPreferencesDao extends AbstractBaseDao<SystemPreferences, Long>{


	@SuppressWarnings("unchecked")
	public SystemPreferences findConfigByKey(String appConfigType){
		Criteria cta = createCriteria();
		cta.add(Restrictions.eq("configTypeKey", appConfigType));
		cta.setMaxResults(1);
		List<SystemPreferences> list = cta.list();
		if (list != null && !list.isEmpty()) {
			return list.get(0);
		}
		return null;
	} 
	
	@SuppressWarnings("unchecked")
	public List<SystemPreferences> findSystemPreferences() {
		Criteria criteria = createCriteria();
		return  criteria.list();
	}
	
	
}
